package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.math.BigDecimal;

public class ENNUMBER extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    String str = "";
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      Object localObject = paramArrayOfObject[i];
      if (localObject instanceof BigDecimal)
        try
        {
          str = NumberToEnglish((BigDecimal)localObject);
        }
        catch (Exception localException)
        {
          str = "ERROR!";
        }
    }
    return str;
  }

  private String NumberToEnglish(BigDecimal paramBigDecimal)
    throws Exception
  {
    int j;
    String str = "";
    int k = paramBigDecimal.intValue();
    if (k >= 20)
    {
      int i = k / 10 * 10;
      j = k - i;
      switch (i)
      {
      case 90:
        str = "NINETY";
        break;
      case 80:
        str = "EIGHTY";
        break;
      case 70:
        str = "SEVENTY";
        break;
      case 60:
        str = "SIXTY";
        break;
      case 50:
        str = "FIFTY";
        break;
      case 40:
        str = "FORTY";
        break;
      case 30:
        str = "THIRTY";
        break;
      case 20:
        str = "TWENTY";
      }
      if (str.trim().length() > 0)
        str = str + " ";
    }
    else
    {
      j = k;
    }
    switch (j)
    {
    case 19:
      str = str + "NINETEEN";
      break;
    case 18:
      str = str + "EIGHTEEN";
      break;
    case 17:
      str = str + "SEVENTEEN";
      break;
    case 16:
      str = str + "SIXTEEN";
      break;
    case 15:
      str = str + "FIFTEEN";
      break;
    case 14:
      str = str + "FOURTEEN";
      break;
    case 13:
      str = str + "THIRTEEN";
      break;
    case 12:
      str = str + "TWELVE";
      break;
    case 11:
      str = str + "ELEVEN";
      break;
    case 10:
      str = str + "TEN";
      break;
    case 9:
      str = str + "NINE";
      break;
    case 8:
      str = str + "EIGHT";
      break;
    case 7:
      str = str + "SEVEN";
      break;
    case 6:
      str = str + "SIX";
      break;
    case 5:
      str = str + "FIVE";
      break;
    case 4:
      str = str + "FOUR";
      break;
    case 3:
      str = str + "THREE";
      break;
    case 2:
      str = str + "TWO";
      break;
    case 1:
      str = str + "ONE";
    }
    return str;
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "ENNUMBER(value):将给定的BigDecimal类型的数字转化成英文金额的字符串。";
  }

  public String getEN()
  {
    return "";
  }
}